package com.pentakill.mo.auth.role.web;

import java.util.List;

import com.pentakill.mo.auth.res.business.ebi.ResEbi;
import com.pentakill.mo.auth.res.vo.ResModel;
import com.pentakill.mo.auth.role.business.ebi.RoleEbi;
import com.pentakill.mo.auth.role.vo.RoleModel;
import com.pentakill.mo.auth.role.vo.RoleQueryModel;
import com.pentakill.mo.util.base.BaseAction;


public class RoleAction extends BaseAction {
	
	public RoleModel rm = new RoleModel();
	public RoleQueryModel rqm = new RoleQueryModel();
	//注入角色业务层
	private RoleEbi roleEbi;
	public void setRoleEbi(RoleEbi roleEbi) {
		this.roleEbi = roleEbi;
	}
	//注入资源业务层
	private ResEbi resEbi;
	public void setResEbi(ResEbi resEbi) {
		this.resEbi = resEbi;
	}
	

	public String list(){
		setDataTotal(roleEbi.getCount(rqm));
		List<RoleModel> roleList = roleEbi.getAll(rqm,pageNum,pageCount);
		put("roleList", roleList);
		return LIST;
	}
	
	public String input(){
		
		List<ResModel> resList = resEbi.getAll();
		put("resList",resList);
		if(rm.getUuid() != null){
			rm = roleEbi.get(rm.getUuid());
			//set->long
			resUuids = new long[rm.getResModels().size()];
			int i = 0;
			for (ResModel res: rm.getResModels()) {
				resUuids [i++] = res.getUuid();
			}
		}
		
		return INPUT;
	}
	//资源uuid
	public long [] resUuids;
	//菜单uuid
	public Long [] menuUuids;
	public String seve(){
		if (rm.getUuid() != null) {
			roleEbi.update(rm,resUuids,menuUuids);
		}else {
			roleEbi.seve(rm,resUuids,menuUuids);
		}
		return TO_LIST;
	}
	
	
}
